package cn.wing.items;

import cn.wing.utils.TransactionInfo;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.network.chat.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.function.Consumer;

public class SaleItem extends AbstractWidget {

    private static final Logger log = LoggerFactory.getLogger(SaleItem.class);

    private final TransactionInfo transactionInfo;

    private final Consumer<TransactionInfo> consumer;

    public SaleItem(int p_93629_, int p_93630_, int p_93631_, int p_93632_, Component p_93633_, TransactionInfo transactionInfos, Consumer<TransactionInfo> consumer) {
        super(p_93629_, p_93630_, p_93631_, p_93632_, p_93633_);
        this.transactionInfo = transactionInfos;
        super.setTooltip(Tooltip.create(p_93633_));
        this.consumer = consumer;
    }

    @Override
    protected void renderWidget(GuiGraphics p_282139_, int p_268034_, int p_268009_, float p_268085_) {
        int u = 0, v = 0;               // 纹理中的起始 UV
        // 画 18×18 的小槽位
        p_282139_.blit(
                AbstractWidget.WIDGETS_LOCATION,
                // 屏幕坐标
                this.getX(), this.getY(),
                u, v,
                18, 18,
                256, 256
        );
        p_282139_.renderItem(transactionInfo.getSellItemStack(), getX(), getY());
        p_282139_.renderItemDecorations(Minecraft.getInstance().font, transactionInfo.getSellItemStack(), getX(), getY());
    }

    @Override
    protected void updateWidgetNarration(NarrationElementOutput p_259858_) {

    }

    @Override
    public void onClick(double p_93634_, double p_93635_) {
        consumer.accept(transactionInfo);

        super.onClick(p_93634_, p_93635_);
    }

}
